package com.nage.components.touch;

import android.util.Log;

import com.nage.components.movement.Physics;
import com.nage.components.movement.RandomMovement;
import com.nage.engine.GameObject;

public class ToggleRandomMovement extends Touchable {

	public ToggleRandomMovement(GameObject p) {
		super(p);
		type = TOGGLE_RANDOM_MOVEMENT;
	}

	@Override
	public void onTouch() {
		Log.v("ToggleRandomMovement", "onTouch() method");
		if(parent.hasComponent(RANDOM_MOVEMENT)) {
			parent.removeComponent(RANDOM_MOVEMENT);
			((Physics)parent.getComponent(PHYSICS)).stop();
			Log.v("ToggleRandomMovement", "Turning OFF random movement");
		} else {
			Log.v("ToggleRandomMovement", "Turning ON random movement");
			RandomMovement temp = new RandomMovement(parent);
			parent.addComponentWhenPossible(temp);
			if(!temp.findLinks()) {
				Log.e("ToggleRandomMovement", "Cannot link RandomMovement componenent");
			}
		}
	}

}
